import { ElMessage, ElMessageBox } from "element-plus";
import { deleteRow } from "@/service/main/system/system";

export function useDeleteRowHook(
  pageName: string,
  id: string | number,
  updateList: () => void
) {
  const url = `/${pageName}/${id}`;
  ElMessageBox.confirm("您确定要删除这一条数据吗?", "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning"
  })
    .then(() => {
      deleteRow(url);
      ElMessage({
        type: "success",
        message: "删除成功！"
      });
      updateList();
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "已撤销删除！"
      });
    });
}
